package com.itheima;

import com.itheima.dao.BookDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class App {
    public static void main(String[] args) {
        //1.加载类路径下的配置文件
        //普通方式加载获取容器对象
        ApplicationContext ctx1 = new ClassPathXmlApplicationContext("applicationContext.xml");
        //测试读取多个配置文件
        ApplicationContext ctx2 = new ClassPathXmlApplicationContext("applicationContext.xml","xxx.xml");
        //2.从文件系统下加载配置文件 (忽略)
//        ApplicationContext ctx = new FileSystemXmlApplicationContext("D:\\workspace\\spring\\spring_10_container\\src\\main\\resources\\applicationContext.xml");

        //根据ID来获取
        BookDao bookDao1 = (BookDao) ctx1.getBean("bookDao");
        //根据id配合XX.class
        BookDao bookDao2 = ctx1.getBean("bookDao",BookDao.class);

        //通过类型来获取
        BookDao bookDao3 = ctx1.getBean(BookDao.class);
        bookDao1.save();


    }
}
